<template>
  <div>
    <div class="pl15 pr27 bgfff">
      <p class="fs18 c38 fbold">{{msg.title}}</p>
      <div class="disflex jsbet">
        <p class="fs12 ca8 pt16 pb25">{{msg.createTime}}</p>
        <div class="cdeepblue fs12 disflex align-cen">
          <button class='bgfff fs12 cdeepblue p0' open-type="share" hover-class="other-button-hover">
            转发
          </button>
          <span class="pl21" @click="collect">{{isCollect ? '已收藏' : '收藏'}}</span>
        </div>
      </div>
    </div>
    <img :src="v" alt="" v-for="(v,k) in msg.photos" mode="aspectFill" :key="k" class="w100p">
    <div class="bgfff pt20 pl15 pr15 pb10">
      <div v-html="msg.details"></div>
    </div>
    <div class="textc disflex w60 h60 bradius50p bgblue disinblock back-btn" @click="page_turn('usercenter')">
      <img src="https://one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/user_add.png" alt="" class="w30 h30 mt15">
    </div>
  </div>
</template>

<script>

  import WXAJAX from '../../utils/request'
  import util from '../../utils/index'
  import { mapGetters } from 'vuex';

  export default {
    name: '',
    components: {},
    data() {
      return{
        dynamicId : 0 ,//文章 ID
        msg:{},
        isCollect : false ,
      }
    },
    mounted() {
      wx.setNavigationBarTitle({
        title: '动态详情'
      });
      this.dynamicId = this.$root.$mp.query.dynamicId || 0 ;
      //获取当前的公司
      this.COMPANYID = wx.getStorageSync('COMPANYID') || 0 ;
      this.inits();
      //判断是否已经收藏
      this.checkCollect();
    },
    onShareAppMessage(e){
      const { companyId, cardId } = this.currentCompany;
      this.addDynamicForwardRecord(cardId, this.dynamicId);
      return {
        path :`/pages/dynamicDetail/main?dynamicId=${this.dynamicId}&companyId=${companyId}&cardId=${cardId}&goType=1`,
        success(e){
          wx.showShareMenu({
            withShareTicket : true
          })
        },
        fail(e){
          console.log('失败-- ',e);
        }
      }
    },
    methods: {
      inits(refresh){
        let v = this ;

        wx.showLoading() ;

        WXAJAX.POST({
          companyId : v.COMPANYID,
          dynamicId : v.dynamicId ,
          refresh: refresh || '',
          cardId: wx.getStorageSync('CARDID'),
        }, '', '/personal/getDynamicInfo').then((data) => {

          wx.hideLoading() ;
          data = data[0];
          data.createTime = util.getdate(data.createTime,'dateTime');
          data.photos = data.photos.split(',');
          v.msg = data ;
        }).catch((err) => {
          console.log(err);
          wx.hideLoading() ;
        })
      },
      page_turn(url){
        wx.reLaunch({url:'../'+url+'/main'})
      } ,
      checkCollect(){//
        WXAJAX.checkCollect({
          itemType : 2 ,
          itemId : this.dynamicId ,
        }).then((data)=>{
          this.isCollect = data.status ;
        }).catch((err)=>{

        })
      },
      collect(){
        wx.showLoading();
        let _url = '' ,
          _request = {} ;
        if(this.isCollect){//取消收藏
          _url = '/personal/delCollection' ;

        }else{//添加收藏
          _url = '/personal/addCollection' ;
        }
        _request = {
          itemType : 2 ,
          itemId : this.dynamicId ,
        };

        WXAJAX.changeCollect(_request , _url ).then((data)=>{

          console.log(data);

          if(data){
            this.isCollect = !this.isCollect ;
          }
          wx.hideLoading() ;

        }).catch((err)=>{
          wx.hideLoading() ;
        });


      }

    },
    computed:{
      ...mapGetters(['currentCompany']),
    }
  }
</script>

<style>
  .back-btn{
    position: fixed;
    bottom: 20px;
    right: 20px;
  }
  page{
    background: #fff;
  }
</style>







